<?php

namespace Celebrio\Util;

use Nette\Object;

/**
 * This class contains static methods used in templates as helpers. It should be
 * refactored to actual helpers when the project moves to Nette 2.0.
 *
 * @todo register methods in this class as actual Latte helpers
 *
 * @author pavel
 */
class Helpers extends Object {

    /** MI stands for MENU ITEM */
    const MI_MARGIN = 50;
    const SM_MARGIN = 30;

    /** MI stands for MENU ITEM */
    const MI_WIDTH = 310;
    const SM_WIDTH = 160;

    public static function menu_width($menu_collection) {
        return self::menu_width_count(count($menu_collection));
    }

	public static function extra_menu_width($menu_collection) {
        return (count($menu_collection)+1) * (self::MI_WIDTH + self::MI_MARGIN) + self::MI_MARGIN;
    }
		
    public static function small_menu_width($menu_collection, $additional_items = 0) {
        $item_count = ceil((count($menu_collection) + $additional_items) * 0.5);
        return $item_count * (self::SM_WIDTH + self::SM_MARGIN) + self::SM_MARGIN;
    }

    public static function pictures_width($menu_collection) {
        $width = 200;
        $margin = 30;
        return count($menu_collection, COUNT_RECURSIVE) * ($width + $margin) + $margin;
    }

    public static function recipients_list($menu_collection) {
        $width = 100;
        $margin = 5;
        return count($menu_collection) * ($width + 2 * $margin);
    }

    public static function menu_width_count($count) {
        return $count * (self::MI_WIDTH + self::MI_MARGIN) + self::MI_MARGIN;
    }

    /**
     * Counts the width of menu item based on number of items, their width,
     * margin. You can also specify number of lines which you want to sort 
     * items in.
     *
     * @param type $collection with items
     * @param type $width width of one item
     * @param type $margin overall margin (left and right)
     * @param type $lines number of lines (expected 1 or 2 but can be possibly higher)
     * @return type int width of menu
     */
    public static function elemtents_width($collection, $width, $margin, $lines, $additional = 0) {
        if($lines === 0) {
            throw new \InvalidArgumentException("Number of lines can not be 0");
        }
        return ceil(count($collection) / $lines) * ($width + $margin) + $additional;
    }
    
}
